﻿/*
 * Created by SharpDevelop.
 * User: V.I.Evgenyev
 * Date: 24.09.2010
 * Time: 15:54
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SQLite;

namespace TreeDB
{
	/// <summary>
	/// Description of Find_Form.
	/// </summary>
	public partial class Find_Form : Form
	{
		public Find_Form()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
//----------------поиск узлов--------------------------------------------------		
		void TextBox1KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode.ToString()=="Return")
			{
				dataGridView1.Rows.Clear ();
				SQLiteConnection cnn = new SQLiteConnection("Data Source = " + db_file_name.Value.ToString() );
				cnn.Open();
 				SQLiteCommand SQLcommand = new SQLiteCommand(cnn);
 				SQLiteParameter ID_name = new SQLiteParameter("@ID_name");
 				SQLcommand.CommandText = "SELECT ID, ID_name FROM maintable WHERE ID_name like @ID_name";
 				SQLcommand.Parameters.Add(ID_name);
				ID_name.Value = textBox1.Text;
				SQLiteDataReader read_data = SQLcommand.ExecuteReader ();
				Find_Form find_Form = new Find_Form();
 				while (read_data.Read ()==true)
 					{
 						dataGridView1.Rows.Add (read_data.GetInt32(0).ToString(),read_data.GetString(1));
 					}
 				cnn.Close();
			
			} 
		}
//----------------выбор найденых узлов-----------------------------------------
		void DataGridView1CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			MainForm main = this.Owner as MainForm;
			if (main != null)
			{
				TreeNode[] find_node = main.treeView1.Nodes.Find (dataGridView1.CurrentRow.Cells[0].Value.ToString(), true);
				TreeNode node_find = (TreeNode) find_node.GetValue (0);
				main.treeView1.SelectedNode = node_find;
				
			}
	
		}
		
		
	}
}
